﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abp.Rebus.Job
{
    public class Cron
    {

        public static string IntervalMinutely(int minutes)
        {
            return string.Format("*/{0} * * * *", minutes);

        }


        public static string Daily()
        {
            return Daily(0);
        }

        public static string Daily(int hour)
        {
            return Daily(hour, 0);
        }

        public static string Daily(int hour, int minute)
        {
            return string.Format("{0} {1} * * *", minute, hour);
        }


        public static string Hourly()
        {
            return Hourly(0);
        }

        public static string Hourly(int minute)
        {
            return string.Format("{0} * * * *", minute);
        }

        public static string Minutely()
        {
            return "* * * * *";
        }

        public static string Monthly()
        {
            return Monthly(1);
        }

        public static string Monthly(int day)
        {
            return Monthly(day, 0);
        }

        public static string Monthly(int day, int hour)
        {
            return Monthly(day, hour, 0);
        }

        public static string Monthly(int day, int hour, int minute)
        {
            return string.Format("{0} {1} {2} * *", minute, hour, day);
        }

        public static string Weekly()
        {
            return Weekly(DayOfWeek.Monday);
        }

        public static string Weekly(DayOfWeek dayOfWeek)
        {
            return Weekly(dayOfWeek, 0);
        }

        public static string Weekly(DayOfWeek dayOfWeek, int hour)
        {
            return Weekly(dayOfWeek, hour, 0);
        }

        public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute)
        {
            return string.Format("{0} {1} * * {2}", minute, hour, (int)dayOfWeek);
        }

        public static string Yearly()
        {
            return Yearly(1);
        }

        public static string Yearly(int month)
        {
            return Yearly(month, 1);
        }

        public static string Yearly(int month, int day)
        {
            return Yearly(month, day, 0);
        }

        public static string Yearly(int month, int day, int hour)
        {
            return Yearly(month, day, hour, 0);
        }

        public static string Yearly(int month, int day, int hour, int minute)
        {
            return string.Format("{0} {1} {2} {3} *", new object[] { minute, hour, day, month });
        }

    }
}
